#!/bin/bash
set -e

echo "Run liblinear with multi-threading"

echo "If block when is downloading. try to remove the proxy"
export https_proxy="http://109.105.1.52:8080"

CurDIR=`pwd`
ExeDIR=/tmp/libsvmtools
train_cmd=$ExeDIR/liblinear-multicore-2.11-2/train

if [ ! -x "$train_cmd" ]; then
    mkdir -p $ExeDIR
    cd $ExeDIR
    wget --no-check-certificate https://www.csie.ntu.edu.tw/~cjlin/libsvmtools/multicore-liblinear/liblinear-multicore-2.11-2.zip
    unzip liblinear-multicore-2.11-2.zip
    cd liblinear-multicore-2.11-2
    make
    cd $CurDIR
fi

echo
echo "Find the best C ..."
echo

#$train_cmd -s 0 -C -n 11 ./Data/svm_input.data
#### output ####
#log2c=  -1.00	rate=22.9921
#log2c=   0.00	rate=23.7828
#log2c=   1.00	rate=24.4595
#log2c=   2.00	rate=24.8775
#log2c=   3.00	rate=24.9717
#log2c=   4.00	rate=24.9203
#log2c=   5.00	rate=24.8056
#log2c=   6.00	rate=24.7096
#log2c=   7.00	rate=24.5948
#log2c=   8.00	rate=24.5409
#log2c=   9.00	rate=24.5143
#log2c=  10.00	rate=24.4578
#warning: maximum C reached.
#Best C = 8.000000  CV accuracy = 24.9717%
################

echo
echo "Try cross validation with best C ..."
echo
$train_cmd -s 0 -c 8 -v 5 -n 11 ./Data/svm_input.data
#### output ####
#iter 11 act 9.645e-01 pre 8.209e-01 delta 9.365e+01 f 4.789e+03 |g| 2.950e+00 CG   4
#iter 12 act 9.864e-02 pre 9.413e-02 delta 9.365e+01 f 4.788e+03 |g| 7.996e-01 CG   5
#iter 13 act 8.833e-04 pre 8.794e-04 delta 9.365e+01 f 4.788e+03 |g| 7.978e-02 CG   5
#Cross Validation Accuracy = 23.1026%
################


